<?php
/**
 * 指标管理类
 * @author w.
 *
 */
class IndicatorManage {
	
	private $indicatorHandle = array();
	private $dbClient = null;
	private $collection = null;
	
	public function setCollection($collection){
		$this->collection = $collection;
	}
	
	
	
	/**
     * @return the $dbClient
     */
    public function getDbClient()
    {
        return $this->dbClient;
    }

    /**
     * @param field_type $dbClient
     */
    public function setDbClient($dbClient)
    {
        $this->dbClient = $dbClient;
    }

    public function addIndicatorHandle($indicator){
		array_push($this->indicatorHandle,$indicator);
		return $this;
	}
	
	public function calc($bars){
		$cnt = count($this->indicatorHandle);
		// 遍历指标计算
		for($n=0;$n<$cnt;$n++){
		    $this->indicatorHandle[$n]->setCollection($this->collection);
		    $this->indicatorHandle[$n]->setDbClient($this->dbClient);
			$bars = $this->indicatorHandle[$n]->calc($bars);
		}
		// 保存到数据库
		$bars = $this->save($bars);
		return $bars;
	}
	
	public function save($bars){
		$cnt = count($this->indicatorHandle);
		// 遍历指标保存
		for($i=0;$i<$cnt;$i++){
			$this->indicatorHandle[$i]->setCollection($this->collection);
			$this->indicatorHandle[$i]->save($bars);
		}
		return $bars;
	}
}

?>
